package com.mmlc.meimei.lichengkongjian;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.multidex.MultiDex;
import android.view.LayoutInflater;

import com.androidnetframe.BaseParentActivity;
import com.androidnetframe.ConfigUtil;
import com.androidnetframe.cache.MyDiskCache;
import com.easemob.helpdeskdemo.DemoApplication;
import com.mmlc.meimei.lichengkongjian.been.User;
import com.mmlc.network.iml.ProcessCodeType;
import com.mmlc.utils.AppUtils;
import com.mmlc.utils.DataCleanManager;

import org.xutils.x;

import java.util.HashMap;
import java.util.Map;

import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.ShareSDK;

/**
 * Created by Administrator on 2016/7/11.
 */
public class App extends DemoApplication {
    public static MyDiskCache diskCache;
    public static LayoutInflater layoutInflater;
    public static Context context;
    public static User user;
    public static BaseParentActivity activity;
    public static Map<String, Activity> activityMap = new HashMap<>();


    public static void setActivity(BaseParentActivity activity) {
        App.activity = activity;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        SharedPreferences clean = getSharedPreferences("DATA_CLEAN", MODE_PRIVATE);
        if(AppUtils.getVersionCode(context) == 8 && !clean.getBoolean("isClean",false)){
            DataCleanManager.cleanApplicationData(context);
            SharedPreferences sp = getSharedPreferences("DATA_CLEAN", MODE_PRIVATE);
            SharedPreferences.Editor edit = sp.edit();
            edit.putBoolean("isClean",true);
            edit.commit();
        }
        x.Ext.init(this);
        x.Ext.setDebug(false);
        //必须要在new之前注册
        ConfigUtil.registerProcessCodeType(ProcessCodeType.class);
        new ConfigUtil(this);
        //创建磁盘缓存目录
        diskCache = new MyDiskCache(getApplicationContext(), "mmCache");
        layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //创建User的全局类
        user = new User(this);
        //初始化分享配置
        initSharedSdk();

//        JPushInterface.setDebugMode(true);// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);// 初始化 JPush

    }
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    private void initSharedSdk() {
        ShareSDK.initSDK(this);
          /*  //微信 appid appsecret
        PlatformConfig.setWeixin(Constants.WX_APP_ID, Constants.WX_APP_SECRET);
        //新浪微博 appkey appsecret
        PlatformConfig.setSinaWeibo(Constants.SINA_APP_KEY, Constants.SINA_APP_SECRET);
        // QQ和Qzone appid appkey
        PlatformConfig.setQQZone(Constants.QQ_APP_ID, Constants.QQ_APP_KEY);*/
    }

}
